package com.yqb.sdk.dialog;

import com.yqb.sdk.util.AtyContainer;
import com.yqb.sdk.util.Common;
import com.yqb.sdk.util.QBUtils;

import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class ExitDialog extends DialogFragment implements OnClickListener {

	private TextView tv_title_exit;
	private Button btn_exit_cancel, btn_exit_confirm;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
		getDialog().setCanceledOnTouchOutside(false);
		View view = inflater.inflate(QBUtils.getResLayout("qb_dialog_exit"),
				null);
		initViews(view);

		return view;
	}

	private void initViews(View view) {
		tv_title_exit = (TextView) view.findViewById(QBUtils
				.getResID("tv_title_exit"));
		tv_title_exit.setVisibility(View.VISIBLE);

		btn_exit_cancel = (Button) view.findViewById(QBUtils
				.getResID("btn_exit_cancel"));
		btn_exit_cancel.setOnClickListener(this);
		btn_exit_confirm = (Button) view.findViewById(QBUtils
				.getResID("btn_exit_confirm"));
		btn_exit_confirm.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == QBUtils.getResID("btn_exit_cancel")) {
			dismiss();
		} else if (v.getId() == QBUtils.getResID("btn_exit_confirm")) {
			Common.exitCallBack.onExit();
			AtyContainer.getInstance().finishAllActivity();
			System.exit(0);
		}

	}

}
